/*
 * @Author: Wangjun
 * @Date: 2023-08-14 10:40:47
 * @LastEditTime: 2023-12-10 12:09:35
 * @LastEditors: wangjun haodreams@163.com
 * @Description:实时库测点模拟量输出（数据写入到实时库）
 * @FilePath: \xr_node_calc\noderdb\op_magus_ao.go
 * hnxr
 */
package noderdb

import (
	"gitee.com/haodreams/godriver/opdb"
	"gitee.com/hnxr_1/nodex"
)

func init() {
	nodex.Reister(new(MagusAO))
}

type MagusAO struct {
	nodex.Node
	item *opdb.Real

	X nodex.Double `remark:"输入1"`
}

func (m *MagusAO) GetModelID() int {
	return nodex.ModOut
}

func (m *MagusAO) Init(mem *nodex.Memory) (err error) {
	outs := make([]*nodex.Out, 1)
	outs[0] = &nodex.Out{Name: "Y", Value: m.X.DoubleValue}
	m.SetOuts(outs)

	extends := m.GetExtends()
	atag := extends["tag"]
	tag, _ := atag.(string)

	m.item = dataitem.GetOPValue(tag, false)

	return
}

func (m *MagusAO) GetName() string {
	return "MagusAO"
}

/**
 * @description: 节点信息
 * @return {*}
 */
func (m *MagusAO) RegData() []byte {
	return nodex.MakeRegData(m, "麦杰实时库模拟量输出", m.GetName(), "")
}

func (m *MagusAO) GetParams() []nodex.Valuer {
	return []nodex.Valuer{&m.X}
}

func (m *MagusAO) Calc() (err error) {
	m.Bad = *m.X.Bad
	m.item.Value = m.X.Value
	if m.Bad {
		m.item.Status = 0x300
	} else {
		m.item.Status = 0
	}
	return
}

func (m *MagusAO) GetResult() (v float64, isBad bool) {
	return m.X.Value, m.Bad
}
